package leetcode.n2021;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 349. 两个数组的交集
 * https://leetcode-cn.com/problems/intersection-of-two-arrays/
 * @author Chaos
 * @version 1.0
 * @date 2020/11/2 14:37
 */
public class Intersection {

    public int[] intersection(int[] nums1, int[] nums2) {
        ArrayList<Integer> infoList = new ArrayList<Integer>();
        for (int i : nums1) {
            for (int j : nums2) {
                if (i == j) {
                    infoList.add(i);
                }
            }
        }
        List<Integer> resultList = infoList.stream().distinct().collect(Collectors.toList());
        int[] objects = new int[resultList.size()];
        for (int i = 0; i < resultList.size(); i++) {
            objects[i] = resultList.get(i);
        }

        return objects;
    }

    public static void main(String[] args) {
        System.out.println( new Intersection().intersection(new int[]{1, 2, 1, 2}, new int[]{2, 2}));
    }
}
